package org.emet.dao;

import java.util.List;

import org.emet.entity.biz.Ceremony;
import org.emet.jee.core.dao.Page;
import org.emet.jee.core.dao.arch.ArchDataSourceBaseDao;
import org.emet.service.dto.CeremonyCriteria;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

@Repository
public class CeremonyDao extends ArchDataSourceBaseDao<Ceremony, Long> {
	public Page<Ceremony> search(Page<Ceremony> page, CeremonyCriteria criteria) {
		Criteria c = getSession().createCriteria(Ceremony.class);
		NonEmptyValueHashMap<String, Object> propertyNameValues = new NonEmptyValueHashMap<String, Object>();
		propertyNameValues.put("reg.bizNo", criteria.getBizNo());
		propertyNameValues.put("type", criteria.getType());
		propertyNameValues.put("fee", criteria.getFee());
		propertyNameValues.put("startDate", criteria.getStartDate());
		propertyNameValues.put("endDate", criteria.getEndDate());
		c.add(Restrictions.allEq(propertyNameValues));
		page.setOrderBy("id");
		page.setOrder("desc");
		return findPage(page, c);
	}

	public List<Ceremony> findUnpaiedByBiz(String bizNo) {
		return find("from Ceremony where paied = false and reg.bizNo = ?", bizNo);
	}

	public void setAsPaied(Long chargeId) {
		Ceremony ceremony = get(chargeId);
		if (null != ceremony) {
			ceremony.setPaied(true);
		}
	}
}
